package bmptest.bmp.controller.menu;

import bmptest.bmp.entity.SysMenu;
import bmptest.bmp.service.SysUser.SysUserService;
import bmptest.bmp.service.Sysmenu.SysMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author lyq
 * @date 2021/9/6 9:49
 * 菜单工具类
 */

@RestController
public class MenuController {

    @Autowired
    private SysMenuService sysMenuService;

    @Autowired
    private SysUserService sysUserService;

    @Autowired
    public RedisTemplate<String,String> redisTemplate;

    @CrossOrigin
    @RequestMapping(value = "/api/querySysMenu",method = RequestMethod.GET)
    public List<SysMenu> querySysMenu(){
        redisTemplate.setKeySerializer(RedisSerializer.string());
        String userid = redisTemplate.opsForValue().get("uid");
        String roleid = sysUserService.queryRoleIdByUserId(userid);
        List<SysMenu> listallmenu = sysMenuService.querySysMenu1(roleid);
        List<SysMenu> treemenu = sysMenuService.buildtree(listallmenu,null);
        return treemenu;
    }



}
